﻿
@using Common
@model Param_AdminUser

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>设置我的密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link href="https://cdn.staticfile.org/layui/2.7.6/css/layui.css" rel="stylesheet">
    <link href="~/Content/layuiadmin/style/admin.css" rel="stylesheet" />
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-container">
            <div class="layui-row">
                <div class="layui-col-xs10 layui-col-xs-offset1">
                    <form class="layui-form" lay-filter="form" style="margin-right:60px;" onsubmit="return false">
                        <div class="layui-form-item">
                            <label for="OldPassWord" class="layui-form-label">当前密码</label>
                            <div class="layui-input-block">
                                <input type="password" name="oldPassword" id="OldPassWord" lay-verify="required" lay-verType="tips" value="@Model.PassWord" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label for="PassWord" class="layui-form-label">新密码</label>
                            <div class="layui-input-block">
                                <input type="password" id="PassWord" name="PassWord" lay-verify="PassWord" placeholder="请输入密码" value="@Model.PassWord" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label for="RepassWord" class="layui-form-label">确认新密码</label>
                            <div class="layui-input-block">
                                <input type="password" id="rePassWord" name="rePassWord" lay-verify="rePassWord" placeholder="请输入确认密码" value="@Model.PassWord" lay-verType="tips" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn sub" lay-submit lay-filter="formDemo">确认修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.staticfile.org/layui/2.7.6/layui.js"></script>
    <script>
        layui.config({
            base: '/Content/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'set']);
    </script>
    <script src="~/Scripts/jquery-3.3.1.min.js"></script>
    <script src="~/Scripts/dist/html5ImgCompress.min.js"></script>
    <script src="~/Scripts/tools.js"></script>
    <script>
    var data = {};
    //Demo
        $(function () {
            layui.use(function () {
                var form = layui.form;
        var upload = layui.upload;
        form.verify({
            PassWord: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value == "" || value == null) {
                    return '不能为空符';
                }
                if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                    return '不能有特殊字符';
                }
                if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                    return '用户名首尾不能出现下划线\'_\'';
                }
                if (/^\d+\d+\d$/.test(value)) {
                    return '密码不能全为数字';
                }
                if (value.length < 6 && value.length > 16) {
                    return '密码不能少于6位，大于16位';
                }
            }

            //我们既支持上述函数式的方式，也支持下述数组的形式
            //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            , rePassWord: function (value, item) { //value：表单的值、item：表单的DOM对象
                if (value != $("#PassWord").val()) {
                    return '两次密码输入不一致';
                }
            }
        });
        form.on('submit(form)', function () {
            // 验证均通过后的操作（如 Ajax 提交）

            var index = layer.load(1, { shade: [0.6, "#fff"] });
            data.PassWord = $("#PassWord").val();
            data.OldPassWord = $("#OldPassWord").val();


            console.log(data);

            $.post(apiurl + "api/AdminUser/UpPass/" + @Model.AdminID, data, function (res) {
                console.log(res);
                if (res.Code == 200) {
                    setTimeout(() => {
                        layer.close(index);
                        layer.msg("修改成功", { icon: 6, time: 1500 });
                        setTimeout(() => {
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                            parent.location.reload();
                        }, 600)
                    }, 300);
                }
                else {
                    layer.msg("修改失败");
                }
            })
        });
            })
        
        })
    </script>
</body>
</html>